{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
    <form class="layui-form gg-form-bar border-x border-t" lay-filter="barsearchform">
		<div class="layui-input-inline" style="width:120px">
			<select name="types">
				<option value="">请选择类型</option>				
				{volist name=":get_content_types(1)" id="v"}
				<option value="{$v.id}">{$v.title}</option>
				{/volist}
			</select>
		</div>
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline" style="width:150px">
			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="table-search"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
			<button type="reset" class="layui-btn layui-btn-reset" lay-filter="table-reset">清空</button>
		</div>
	</form>
	
	<table class="layui-hide" id="test" lay-filter="test"></table>
	</div> 
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
	<button class="layui-btn layui-btn-sm" lay-event="add">
		<span>+ 新增课程内容</span>
		<i class="layui-icon layui-icon-down layui-font-12"></i>
	</button>
  </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
	<script>	
	const course_types = {:json_encode(get_content_types(1),JSON_UNESCAPED_UNICODE)};
	const moduleInit = ['tool','tablePlus'];
	function gouguInit() {
		var table = layui.tablePlus, tool = layui.tool,form = layui.form,dropdown = layui.dropdown;
		
		layui.pageTable = table.render({
			elem: '#test'
			,toolbar: '#toolbarDemo'
			,title:'课程内容列表'
			,url: "/course/material/datalist"
			,page: true
			,limit: 20
			,height: 'full-114'
			,cellMinWidth: 80
			,cols: [[
				{field:'id',width:80, title: 'ID号', align:'center'}
				,{field:'types_str', title: '类型',width:80,align:'center'}
				,{field:'title',title: '名称'}
				,{field:'duration_str',title: '课时时长',width:142, align:'center'}
				,{field:'admin_name',title: '创建人',width:90,align:'center'}
				,{field:'create_time',title: '创建时间',width:150,align:'center'}
				,{width:132,title: '操作', align:'center',templet: function(d){
					var btn='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
					var btn1='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">查看</a>';
					var btn2='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
					return '<div class="layui-btn-group">'+btn+btn1+btn2+'</div>';
				}}
			]]
		});
		
		table.on('tool(test)',function (obj) {
			if(obj.event === 'edit'){					
				tool.side("/course/material/add?id="+obj.data.id);
			}
			if(obj.event === 'view'){					
				tool.side("/course/material/view?id="+obj.data.id);
			}
			if(obj.event === 'del'){
				layer.confirm('确定要删除该数据吗?', {icon: 3, title:'提示'}, function(index){
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							layui.pageTable.reload();
						}
					}
					tool.delete("/course/material/delete", { id: obj.data.id}, callback);
					layer.close(index);
				});
			}
		});
		
		//表头工具栏事件
		table.on('toolbar(test)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
			var data = checkStatus.data;
			var that = this;
			if (obj.event === 'add'){
				  dropdown.render({
					elem: that,
					show: true, // 外部事件触发即显示
					data: course_types,
					click: function(obj){
						tool.side("/course/material/add?types="+obj.id);
					}
				  });
				return;
			}
		});	
	}
	</script>
{/block}
<!-- /脚本 -->